package service

import (
	"context"
	"errors"
	"video_server/basic/appConfig"
	__ "video_server/basic/proto"
	"video_server/handler/models"
)

// server is used to implement helloworld.GreeterServer.
type Server struct {
	__.UnimplementedVideoServer
}

// SayHello implements helloworld.GreeterServer
func (s *Server) AddVideo(_ context.Context, in *__.AddVideoReq) (*__.AddVideoResp, error) {
	var err error
	var v models.Video

	v.Title = in.Title
	v.AuthorId = in.AuthorId
	v.CoverUrl = in.CoverUrl
	v.Likes = in.Likes
	v.CollectCount = in.CollectCount
	if err = v.AddVideo(appConfig.DB); err != nil {
		return nil, errors.New("视频发布失败")
	}

	return &__.AddVideoResp{
		VideoId: 1,
	}, nil
}
